//
//  BasePageTableCell.m
//  Village
//
//  Created by 程虎 on 2017/9/6.
//  Copyright © 2017年 程虎. All rights reserved.
//

#import "HomeTableCell.h"

@implementation HomeTableCell

+ (instancetype)cellWithTableView:(UITableView *)tableView
{
    static NSString *cellID = @"HomeTableCell";
    HomeTableCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    return cell;
}

- (void)setModel:(VillageModel *)model
{
    _model = model;
    [self.icon sd_setImageWithURL:[NSURL URLWithString:[Tools resolutionHeadImage:_model.upimg]] placeholderImage:[UIImage imageNamed:@"default_img"]];

    self.titleLab.text = _model.title;

    NSString *name = _model.nickname.length > 0 ? _model.nickname : _model.publishuser;
    NSString *times = _model.publishtime.length > 0 ? _model.publishtime : @"";
    if (times.length > 0){
        times = [times substringToIndex:19];//截取掉下标7之后的字符串
    }
    NSString *red = _model.readnum;
    if (red == nil){
        red = @"0";
    }else{
        
    }
    self.contentLab.text = [NSString stringWithFormat:@"%@·%@  %@阅读",name,times,red];
    
//    if ([_model.upimg isEqualToString:@"[null]"]){
//        self.icon.hidden = YES;
//        self.icon.sd_layout
//        .widthIs(0.1)
//        .heightIs(50);
//    }else{
//        NSLog(@"有图片");
//        self.icon.sd_layout
//        .widthIs(85)
//        .heightIs(64);
//    }

    if (_model.upimg.length > 0){
        NSLog(@"有图片");
        self.icon.sd_layout
        .widthIs(85)
        .heightIs(64);
    }else{
        self.icon.hidden = YES;
        self.icon.sd_layout
        .widthIs(0.1)
        .heightIs(50);

    }


    
}

- (void)setModel1:(PolicyModel *)model1
{
    _model1 = model1;
    self.titleLab.text = _model1.title;
    
    NSString *red = _model1.readnum;
    if (_model1.readnum == nil){
        red = @"0";
    }else{

    }
    self.contentLab.text = [NSString stringWithFormat:@"%@·%@  %@阅读",_model1.creator,[_model1.publishtime substringToIndex:10],red];
    
    self.icon.sd_layout
    .widthIs(0.1)
    .heightIs(50);
}

- (void)awakeFromNib {
    [super awakeFromNib];
    
    CGFloat left = 12;
    CGFloat top = 14.5;
    CGFloat left_m = 15;
    
    self.icon.sd_layout
    .leftSpaceToView(self.contentView, left)
    .topSpaceToView(self.contentView, top)
    .widthIs(85)
    .heightIs(64);
    
    self.titleLab.sd_layout
    .leftSpaceToView(self.icon, left_m)
    .topEqualToView(self.icon)
    .rightSpaceToView(self.contentView, left)
    .autoHeightRatio(0)
    .maxHeightIs(70);
    
    self.contentLab.sd_layout
    .leftEqualToView(self.titleLab)
//    .bottomEqualToView(self.icon).offset(-5)
    .topSpaceToView(self.titleLab, 22)
    .rightEqualToView(self.titleLab)
    .heightIs(11);
    
    self.line.sd_layout
    .leftSpaceToView(self.contentView, 0)
    .bottomSpaceToView(self.contentView, 0)
    .rightSpaceToView(self.contentView, 0)
    .heightIs(0.5);
    
    [self setupAutoHeightWithBottomViewsArray:@[self.icon,self.contentLab] bottomMargin:top];
}


@end
